package com.example.test2018131379.controller;

import com.example.test2018131379.bean.UserBean;
import com.example.test2018131379.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Resource
    UserService userService;

    @RequestMapping("/login")
    public String show(){
        return"login";
    }

    @RequestMapping(value = "/loginAction",method = RequestMethod.POST)
    public String loginAction(String name, String password, HttpSession session) {
        UserBean userBean = userService.loginAction(name, password);
        if (userBean != null) {
            session.setAttribute("user",userBean);
            return "success";
        } else {
            return "error";
        }
    }
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "index";
    }
}